package paixu;

import java.util.Stack;

public class TT {

    public static void main(String[] args) {
        
       
        char[] a = "ahahaha".toCharArray();
        int len, mid, next;

        len = a.length; // 求字符串的长度
        mid = len / 2;

        Stack<Character> sc1 = new Stack<Character>(); //栈的初始化
        // 将mid前的字符依次入栈
        for (int i = 0; i < mid; i++)
            sc1.push(a[i]);

        // 判断字符串的长度的是奇数还是偶数，并找出需要进行字符匹配的起始下标
        if (len % 2 == 0)
            next = mid;
        else
            next = mid + 1;

        // 开始匹配
        for (int i = next; i <= len - 1; i++) {
            if (a[i] != sc1.peek()) {
                break;
            } else {
                sc1.pop();
            }
        }
        // 如果top的值为0，则说明栈内的所有的字符都被一一匹配了
        if (sc1.isEmpty())
            System.out.println("YES");
        else
            System.out.println("NO");

        
        
        
        int count = 0;
        String s = "(((())()()))";
        Stack<Character> sc = new Stack<Character>();
        char[] c = s.toCharArray();
        for (int i = 0; i < c.length; i++) {
            if (c[i] == '(' || c[i] == '[' || c[i] == '{') {
                sc.push(c[i]);
            } else if (c[i] == ')') {
                if (sc.peek() == '(') {
                    sc.pop();
                    count++;
                }
            } else if (c[i] == ']') {
                if (sc.peek() == '[') {
                    sc.pop();
                }
            } else if (c[i] == '}') {
                if (sc.peek() == '{') {
                    sc.pop();
                }
            }
        }
        if (sc.empty()) {
            System.out.println("成对");
        } else {
            System.out.println("不成对");
        }

        System.out.println(count);
    }
}
